<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        tr,td{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<table class="layui-table" id="test_table">
    <thead>
    <tr>
        <td>商品名称</td>
        <td>卖出数(个)</td>
        <td>剩余数(个)</td>
        <td>已结算数(个)</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {foreach $result as $val}
    <tr>
        <td>{$val.pname}</td>
        <td>{$val.sellnumber}</td>
        <td>{$val.number - $val.sellnumber}</td>
        {if isset($val.anumber)}
            <td>{$val.anumber}</td>
        {else/}
            <Td>0</Td>
        {/if}
        <td>
            {if isset($val.anumber)}
                <button type="button" onclick="settlement({$val.id},{$val.sellnumber - $val.anumber},{$sid},{$pid},{$bid})" class="btn btn-primary btn-xs">结算</button>
            {else/}
                <button type="button" onclick="settlement({$val.id},{$val.sellnumber},{$sid},{$pid},{$bid})" class="btn btn-primary btn-xs">结算</button>
            {/if}
        </td>
    </tr>
    {/foreach}
    </tbody>
</table>
</body>
<script>
    //结算
    function settlement(inventoryid,sellnumber,sid,pid,bid) {
        if(sellnumber <= 0){
            layer.alert('此订单无需结算');
            return ;
        }
        window.location.href = "{:url('index/postbusiness/settlement')}?inventoryid="+inventoryid+"&sellnumber="+sellnumber+"&sid="+sid+"&bid="+bid+"&pid="+pid;
    }
</script>
</html>